﻿using System;
using System.IO;
using MIAP.Negocio.Utiles;

namespace MIAPWEB.Forms.Controles
{
    public partial class wucListaErrores : System.Web.UI.UserControl
    {
        /// <summary>
        /// Opropiedad que contiene la lista de errores que sera descargada
        /// </summary>
        public string ListaErrores
        {
            get { return this.ViewState["ListaErrores"].ToString(); }
            set { this.ViewState["ListaErrores"] = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnDescargarErrores_onClick(object sender, EventArgs e)
        {
            this.Response.Clear();
            this.Response.ClearContent();
            this.Response.ClearHeaders();

            // Open the file into a stream. 
            Stream stream = StringAndStream.GenerateStreamFromString(this.ListaErrores);
            // Total bytes to read: 
            var bytesToRead = stream.Length;
            stream.Close();
            // Nos aseguramos que el cliente siga conectado
            if (!Response.IsClientConnected) return;
            Response.ContentType = "text/plain";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + "Errores.txt");
            Response.AddHeader("Content-Length", bytesToRead.ToString());
            Response.Write(this.ListaErrores);
            Response.End();

        }


    }
}
